<template>
  <div>
    <t-table rowKey="id" :data="data" :columns="columns" hover :pagination="pagination" :loading="dataLoading">
      <template #name="{ row }">
        <!--      <t-link @click="dialog.objId=row.id;dialog.header=row.name;dialog.open_innovation_detail=true" hover="color" theme="primary">{{row.name}}</t-link>-->
        {{ row.name }}
      </template>
      <template #applicationField="{ row }">
        {{ row.applicationField | filterByDict(dict.type.application_field) }}
      </template>
      <template #innovationCategory="{ row }">
        {{ row.innovationCategory | filterByDict(dict.type.innovation_category) }}
      </template>
      <!--    <template #innovationStatus="{ row }">-->
      <!--      <t-tag  @click="dialog.header='审批记录';dialog.objId=row.id;dialog.open_approve_list=true" class="cursor-pointer" :theme="handleTheme(row.innovationStatus, dict.type.innovation_status)" variant="light">-->
      <!--        {{ row.innovationStatus | filterByDict(dict.type.innovation_status) }}-->
      <!--      </t-tag>-->
      <!--    </template>-->

      <!--    <template #op="{ row }">-->
      <!--      <t-button @click="dialog.header=row.name;dialog.objId=row.id;dialog.open_innovation_detail=true" size="small" variant="text" class="t-button-link">-->
      <!--        <t-icon name="info-circle" slot="icon"/>-->
      <!--        详情-->
      <!--      </t-button>-->
      <!--    </template>-->
    </t-table>
    <innovation-detail-dialog :header="dialog.header" :objId="dialog.objId"
      :visible.sync="dialog.open_innovation_detail" v-if="dialog.open_innovation_detail"></innovation-detail-dialog>
    <approve-list :header="dialog.header" :objId="dialog.objId" :visible.sync="dialog.open_approve_list"
      v-if="dialog.open_approve_list"></approve-list>
  </div>
</template>

<script>
import approveList from "../../../wcx/approve/components/approve-list.vue";

export default {
  name: "wcx-list",
  dicts: ["application_field", "innovation_category", "approve_status", "innovation_status"],
  props: ["deptId", 'idCard'],
  components: {
    // innovationDetailDialog,
    approveList,
    innovationDetailDialog: () => import('../../../wcx/innovation/components/innovation-detail-dialog.vue'),
  },
  data () {
    return {
      dialog: {
        header: "",
        objId: 0,
        open_innovation_detail: false,
        open_approve_list: false,
      },
      data: [],
      columns: [
        {
          colKey: "name",
          title: "成果名称",
          align: "center",
          width: 220
        },
        {
          colKey: "applicationProject",
          title: "应用项目",
          align: "center",
        },
        {
          colKey: "applicationField",
          title: "应用领域",
          align: "center",
        },
        {
          colKey: "innovationCategory",
          title: "创新类别",
          align: "center",
        },
        {
          colKey: "leaderName",
          title: "负责人",
          align: "center",
        },
        {
          colKey: "deptName",
          title: "工作单位",
          align: "center",
        },
        // {
        //   colKey: "innovationStatus",
        //   title: "成果状态",
        //   align: "center",
        //   width:120
        // },
        // {
        //   colKey: "approveStatus",
        //   title: "审批状态",
        //   align: "center",
        //   width:120
        // },

        {
          colKey: "createTime",
          title: "申报时间",
          align: "center",
          width: 200
        },
        // {
        //   colKey: "op",
        //   title: "操作",
        //   align: "center",
        //   width: 120
        // },
      ],
      dataLoading: false,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        applicationField: '',
        innovationCategory: '',
        name: '',
        innovationStatus: '',
        leaderName: '',
        deptName: '',
        deptId: this.deptId,
        idCard: this.idCard,
      },
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0,
        showPageSize: true,
        pageSizeOptions: [10, 20, 30],
        showFirstAndLastPageBtn: false,
        onChange: (pageInfo) => {
          Object.assign(this.pagination, pageInfo)
          this.queryParams.pageNum = pageInfo.current || 1;
          this.queryParams.pageSize = pageInfo.pageSize;
          this.getList()
        },
      },
    }
  },
  created () {
    this.getList();
  },
  methods: {
    getList () {
      if (this.deptId) {
        this.dataLoading = true;
        this.$api.wcx.innovation.list(this.queryParams).then(
          (res) => {
            this.data = res.rows;
            this.pagination.total = res.total;
            this.dataLoading = false;
          }).catch((e) => {
            this.dataLoading = false;
            this.$message.error(e.toString());
          });
      } else if (this.idCard) {
        this.dataLoading = true;
        this.$api.wcx.innovation.myJoinList(this.queryParams).then(
          (res) => {
            this.data = res.rows;
            this.pagination.total = res.total;
            this.dataLoading = false;
          }).catch((e) => {
            this.dataLoading = false;
            this.$message.error(e.toString());
          });
      }
    },
  }
}
</script>

<style scoped></style>
